<?php
Yii::import("application.website.*");
Yii::import("application.website.adapter.*");

$url = ArchiveUrl::getNext();
$url->fetched = time();
if ($url == null) break;
if (strpos($url->url, "index") == 0) {
	$url->broken = time();
	$url->update();
	return;
}
$url->update();
echo "<div id='url'>".$url->url."</div>";
$params = WebsiteUtil::getParams($url->url);
if ($params['page'] != 'User') {
	$content = file_get_contents($url->url);
	$adapter = new WBBIndexWebsiteAdapter();
	$boardAdapter = new WBBBoardWebsiteAdapter();
	$threadAdapter = new WBBThreadWebsiteAdapter();
	$website = new Website($url->url, $content);
	if ($adapter->matches($url->url)) $adapter->parse($website);
	if ($boardAdapter->matches($url->url)) $boardAdapter->parse($website);
	if ($threadAdapter->matches($url->url)) $threadAdapter->parse($website);
}

//return statistics
$statistics = WebsiteUtil::getStatistics();
echo "<div id='statistics'><div id='total'>".$statistics['total']."</div><div id='threads'>".$statistics["threadCount"]."</div><div id='categories'>".$statistics["categoryCount"]."</div><div id='posts'>".$statistics['postCount']."</div><div id='unfetched'>".$statistics['unfetched']."</div></div>";
?>